package com.hnucm.cooklife.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hnucm.cooklife.R;
import com.hnucm.cooklife.adapter.CollectAdapter;
import com.hnucm.cooklife.adapter.MyDishAdapter;
import com.hnucm.cooklife.adapter.RecomAdapter;
import com.hnucm.cooklife.base.BaseFragment;
import com.hnucm.cooklife.base.utils.LoginUtils;
import com.hnucm.cooklife.bean.db.Dish;
import com.hnucm.cooklife.bean.me.DishColl;
import com.hnucm.cooklife.contract.realDish.Contract;
import com.hnucm.cooklife.presenter.me.RealDishPresenter;
import com.hnucm.cooklife.ui.activity.DishDetailActivity;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class RealDishFragment extends BaseFragment<Contract.IReadDishView, RealDishPresenter> implements Contract.IReadDishView {

    private Context mContext;
    private int userid;

    private List<DishColl> mDishCollList = new ArrayList<>();

    @BindView(R.id.cohis_recycler)
    RecyclerView mRecyclerView;


    private CollectAdapter mAdapter;

    @Override
    protected int getContentViewId() {
        return R.layout.co_his_fragment;
    }

    @Override
    protected void init() {
        mContext = getContext().getApplicationContext();
        userid = LoginUtils.getLoginId();
        initAdapter();
        mPresenter.loadRealMyDish(userid);

    }
    private void initAdapter() {
        LinearLayoutManager manager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(manager);
        mAdapter = new CollectAdapter(mContext,mDishCollList);
        mRecyclerView.setAdapter(mAdapter);
//        GridLayoutManager manager = new GridLayoutManager(mContext, 2);
//        mRecyclerView.setLayoutManager(manager);
//        mAdapter = new CollectAdapter(mContext,mDishCollList);
//        mRecyclerView.setAdapter(mAdapter);
//        mAdapter.setOnItemClickListener(new RecomAdapter.onItemClickListener() {
//            @Override
//            public void onSeleClickListener(View view, int position) {
//                Intent intent = new Intent(getActivity(), DishDetailActivity.class);
//                intent.putExtra("dishId",mDishCollList.get(position).dishId);
//                Dish dish = li.get(position);
//
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                startActivity(intent);
//            }
//        });
    }


    @Override
    protected RealDishPresenter createPresenter() {
        return new RealDishPresenter();
    }

    @Override
    public void onLoading() {

    }

    @Override
    public void onLoadingFailed() {

    }

    @Override
    public void onLoadSuccess() {

    }

    @Override
    public void onLoadRealMyDish(List<DishColl> dishCollList) {

        mDishCollList.clear();
        mDishCollList.addAll(dishCollList);
        mAdapter.setDishList(mDishCollList);
    }

    @Override
    public void onRefreshRealMyDish(List<DishColl> dishCollList) {

    }
}
